package com.bsh.serviceImpl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bsh.dto.CloudUserGoodsListQryDto;
import com.bsh.mybatis.model.CloudUserGoods;
import com.bsh.repository.DaoCloudUserGoods;
import com.bsh.service.UserGoodsService;
import com.bsh.utils.Pager;
import com.mysql.jdbc.StringUtils;

/**
 * 用户兑换积分商品
 * @author Administrator
 *
 */
@Service
@Transactional
public class UserGoodsServiceImpl implements UserGoodsService{
    @Autowired
    DaoCloudUserGoods daoUserGoods;
	
	@Override
	public List<Map<String, Object>> getPage(Pager pager, CloudUserGoodsListQryDto qryParam) {
		StringBuilder sb = new StringBuilder();
		if (!StringUtils.isNullOrEmpty(qryParam.getUserName()))
			sb.append(String.format(" and u.name like '%%%s%%'", qryParam.getUserName().trim()));
		if (!StringUtils.isNullOrEmpty(qryParam.getMobile()))
			sb.append(String.format(" and ug.mobile like '%%%s%%'", qryParam.getMobile().trim()));
		if (qryParam.getIsSend()!=null && qryParam.getIsSend()!=-1)
			sb.append(String.format(" and ug.is_send = %s", qryParam.getIsSend()));	
		List<Map<String, Object>> list = daoUserGoods.getPage(pager, sb.toString());
		return list;
	}

	@Override
	public int sendGoods(int merchantId, boolean isSend, String auditMsg) {
		return daoUserGoods.audit(merchantId, isSend, auditMsg);
	}

	@Override
	public CloudUserGoods getUserGoods(int ugid) {
		return daoUserGoods.selectByPrimaryKey(ugid);
	}

}
